/*
 * @Author: your name
 * @Date: 2022-02-17 15:12:52
 * @LastEditTime: 2022-02-17 17:11:31
 * @LastEditors: Please set LastEditors
 * @Description: 频道
 * @FilePath: \geek-app\src\compontens\Channel\index.js
 */

import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { getChannelsAction, saveCurrentAction } from 'store/action/channel.js';

export function Channel() {
  const dispatch = useDispatch();
  useEffect(() => {
    dispatch(getChannelsAction());
  }, [dispatch]);

  const { list, current } = useSelector((state) => state.channel);
  return (
    <ul className="category">
      {list.map((item) => (
        <li
          key={item.id}
          className={item.id === current ? 'select' : ''}
          onClick={() => dispatch(saveCurrentAction(item.id))}
        >
          {item.name}
        </li>
      ))}
    </ul>
  );
}
